package com.Day6;

import java.util.Stack;

public class P4 {
    public int[] dailyTemperatures(int[] temperatures) {
        Stack stack1 = new Stack();
        int[] ans = new int[temperatures.length];
        for(int i = 0; i < temperatures.length; i++){

            if(stack1.isEmpty() &&temperatures[i] > temperatures[(int)stack1.peek()]){
                int index = (int) stack1.pop();
                ans[index] = i - index;
            }
            stack1.push(temperatures[i]);
        }
        return ans;
    }

}
